package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.YxDeviceAndApp;
import com.ruoyi.system.service.IYxDeviceAndAppService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 用户设备应用关系Controller
 * 
 * @author lingyu
 * @date 2024-03-04
 */
@RestController
@RequestMapping("/system/app")
public class YxDeviceAndAppController extends BaseController
{
    @Autowired
    private IYxDeviceAndAppService yxDeviceAndAppService;

    /**
     * 查询用户设备应用关系列表
     */
    @PreAuthorize("@ss.hasPermi('system:app:list')")
    @GetMapping("/list")
    public TableDataInfo list(YxDeviceAndApp yxDeviceAndApp)
    {
        startPage();
        List<YxDeviceAndApp> list = yxDeviceAndAppService.selectYxDeviceAndAppList(yxDeviceAndApp);
        return getDataTable(list);
    }

    /**
     * 导出用户设备应用关系列表
     */
    @PreAuthorize("@ss.hasPermi('system:app:export')")
    @Log(title = "用户设备应用关系", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, YxDeviceAndApp yxDeviceAndApp)
    {
        List<YxDeviceAndApp> list = yxDeviceAndAppService.selectYxDeviceAndAppList(yxDeviceAndApp);
        ExcelUtil<YxDeviceAndApp> util = new ExcelUtil<YxDeviceAndApp>(YxDeviceAndApp.class);
        util.exportExcel(response, list, "用户设备应用关系数据");
    }

    /**
     * 获取用户设备应用关系详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:app:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(yxDeviceAndAppService.selectYxDeviceAndAppById(id));
    }

    /**
     * 新增用户设备应用关系
     */
    @PreAuthorize("@ss.hasPermi('system:app:add')")
    @Log(title = "用户设备应用关系", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody YxDeviceAndApp yxDeviceAndApp)
    {
        return toAjax(yxDeviceAndAppService.insertYxDeviceAndApp(yxDeviceAndApp));
    }

    /**
     * 修改用户设备应用关系
     */
    @PreAuthorize("@ss.hasPermi('system:app:edit')")
    @Log(title = "用户设备应用关系", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody YxDeviceAndApp yxDeviceAndApp)
    {
        return toAjax(yxDeviceAndAppService.updateYxDeviceAndApp(yxDeviceAndApp));
    }

    /**
     * 删除用户设备应用关系
     */
    @PreAuthorize("@ss.hasPermi('system:app:remove')")
    @Log(title = "用户设备应用关系", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(yxDeviceAndAppService.deleteYxDeviceAndAppByIds(ids));
    }
}
